import { createApp } from 'vue'
import App from './App.vue'
import '@/styles/index.scss'
// 组件库相关
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
//@ts-ignore
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
// 引入暗黑模式
import 'element-plus/theme-chalk/dark/css-vars.css'
import pinia from './store/index'
import router from './router'
// 引入路由守卫
import './permission';
import globalComponent from '@/components/index';

import vDebounce from '@/directives/vDebounce';
import debounce from './directives/debounce'

const app = createApp(App);
app.directive('debounce', debounce);
app.directive('vDebounce', vDebounce);

// 首先注册Pinia store
app.use(pinia);
// 然后注册全局组件
app.use(globalComponent);
// 最后注册路由，确保store已正确加载
app.use(ElementPlus, {
  locale: zhCn,
});
app.use(router);

console.log('应用初始化完成', {
  routes: router.getRoutes().length,
  hasStore: !!pinia
});

app.mount('#app');